package com.android.justcook;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;
import camp.android.justcook.R;

public class BaseActivity extends Activity{

	public static final String PREFS_NAME = "PrefsFile";
	public static final String POINTS = "User_points";
	
	@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_finished, menu);
        
        MenuItem item1 = menu.findItem(R.id.menu_commands);     //calling an activity from the action bar
        MenuItem item2 = menu.findItem(R.id.Fav);
               

        item1.setOnMenuItemClickListener
        (
            new MenuItem.OnMenuItemClickListener () 
            { 
                public boolean onMenuItemClick(MenuItem item) 
                { return (callHelp(item)); }
            } 
        ); 
        /*item2.setOnMenuItemClickListener
        (
            new MenuItem.OnMenuItemClickListener () 
            { 
                public boolean onMenuItemClick(MenuItem item) 
                { return (callFav(item)); }
            } 
        );*/
        
        return true;
    }
    public boolean callHelp (MenuItem item)
    {
 	   Intent intent = new Intent(this, HelpActivity.class);
 	   startActivity(intent);
 	   return true;
    }
    public boolean callFav (MenuItem item)
    {
 	   Intent intent = new Intent(this, HelpActivity.class);
 	   startActivity(intent);
 	   return true;
    }
   
   public void goHome (View view) {
	   Intent intent = new Intent(this, MainActivity.class);
	   startActivity(intent);
   }
   
   @Override
   public boolean onOptionsItemSelected(MenuItem item) {
       switch (item.getItemId()) {
           case android.R.id.home:
               NavUtils.navigateUpFromSameTask(this);
               return true;
       }
       return super.onOptionsItemSelected(item);
   }
   
   @Override
   protected void onCreate(Bundle bundle)
   {
	   super.onCreate(bundle);
	   SharedPreferences prefs = getSharedPreferences(PREFS_NAME,0);
	   int progress = prefs.getInt(POINTS, 0);
	   
	   ProgressBar pb = (ProgressBar) findViewById(R.id.progress_bar);
	   if(pb != null)
	   {
		   pb.setProgress(progress);
		   TextView progress_text = (TextView) findViewById(R.id.level_points);
		   progress_text.setText(progress + "/100");
	   }
   }
}
